//
//  MBProgressHUD+Utils.m
//  YZStock
//
//  Created by fenchol on 15/8/27.
//  Copyright (c) 2015年 cqjr. All rights reserved.
//

#import "MBProgressHUD+Utils.h"
#import "YZMControllerManager.h"
#import <objc/runtime.h>

static char hudKey;

@implementation MBProgressHUD (Utils)

@dynamic progressHud;

+ (void)showLoadingWithMsg:(NSString *)msg{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo: [[YZMControllerManager sharedManager] currentNavationCtroller].view animated: YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = msg;
    hud.removeFromSuperViewOnHide = YES;
    objc_setAssociatedObject(self, &hudKey, hud, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

+ (void)hiddenLoading{
    MBProgressHUD *hud =  objc_getAssociatedObject(self, &hudKey);
    hud.hidden = YES;
}

+ (MBProgressHUD *)showMessage: (NSString *)message
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo: [[YZMControllerManager sharedManager] currentNavationCtroller].view animated: YES];
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabelFont = [UIFont systemFontOfSize: 17];
    hud.detailsLabelText = message;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide: YES afterDelay: 1];
    return hud;
}

+ (MBProgressHUD *)showMessageManual: (NSString *)message
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo: [[YZMControllerManager sharedManager] currentNavationCtroller].view animated: YES];
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabelFont = [UIFont systemFontOfSize: 17];
    hud.detailsLabelText = message;
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}

+ (MBProgressHUD *)showProgressMessage: (NSString *)message
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo: [[YZMControllerManager sharedManager] currentNavationCtroller].view animated: YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = message;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide: YES afterDelay: 1];
    return hud;
}

+ (MBProgressHUD *)showProgressMessageManual: (NSString *)message
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo: [[YZMControllerManager sharedManager] currentNavationCtroller].view animated: YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = message;
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}

@end
